package com.book.service.impl;

import com.book.config.JwtUtil;
import com.book.model.ConsumerRecord;
import com.book.mapper.ConsumerRecordDao;
import com.book.service.ConsumerRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.jsonwebtoken.Claims;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wx
 * @since 2023-10-16 09:39:27
 */
@Service
@SpringBootTest
public class ConsumerRecordServiceImpl extends ServiceImpl<ConsumerRecordDao, ConsumerRecord> implements ConsumerRecordService {

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private ConsumerRecordDao consumerRecordDao;

    @Override
    @Test
    public void submitReader(String unauthorized, Long money, String remark) {
        Claims claims = jwtUtil.parseJwt(unauthorized);
        String id = claims.getId();
        ConsumerRecord consumerRecord = new ConsumerRecord();
        BigDecimal bigDecimal = new BigDecimal(money);
        consumerRecord.setConsumerFee(bigDecimal);
        consumerRecord.setReaderId(new Long(id));
        consumerRecord.setConsumerRemark(remark);
        consumerRecordDao.insert(consumerRecord);
    }

    @Test
    public void Test(){
        String zed = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI1Iiwic3ViIjoie1wiaWRcIjo1LFwicGFzc3dvcmRcIjpcIjgxZDA3NjU4NGRmZGQ2YTI5YTNlY2YzNDRiYWJlZjU1XCIsXCJzYWx0XCI6XCI2MzA2MDg0NlwiLFwidXNlcm5hbWVcIjpcImxpc2kxNlwifSIsImlhdCI6MTY5NzQyMTA1MSwicm9sZXMiOiJyb2xlMSIsImV4cCI6MTcwMDAxMzA1MX0.Mejerq1TFHnsqvBQTyIqbX6iVKBQv8fV2cc4NBMhhU4";
        Claims claims = jwtUtil.parseJwt(zed);
        String id = claims.getId();
        System.out.println(id);
    }
}
